package org.csu.mybigpro.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.csu.mybigpro.domain.Question;
import org.csu.mybigpro.persistence.QuestionMapper;
import org.csu.mybigpro.service.IQuestionService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> implements IQuestionService {

    @Override
    public String findSummarizedQuestionsByCourse(String courseName) {
        // 使用MyBatis-Plus的QueryWrapper来构建查询条件
        QueryWrapper<Question> queryWrapper = new QueryWrapper<>();
        // 假设数据库中存储课程名称的字段是 'course_name'
        queryWrapper.eq("course_name", courseName);

        List<Question> questions = this.list(queryWrapper);

        if (questions == null || questions.isEmpty()) {
            return "数据库中没有找到关于《" + courseName + "》的任何问题记录。";
        }

        // 将问题内容拼接成一个摘要，供AI进一步分析
        String summary = questions.stream()
                .map(Question::getContent)
                .collect(Collectors.joining("', '", "共有" + questions.size() + "个相关问题，内容分别是：'", "'。"));

        return summary;
    }
}